package com.tom.architect02.zframework.sreenAdapter;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

/**
 * Added by Tom on 2024/04/11.
 * AndroidManifest.xml--application标签中。 配置设计稿宽高、dpi。 利用缩放来实现适配。
 * <meta-data
 * android:name="designwidth"
 * android:value="1080" />
 * <meta-data
 * android:name="designdpi"
 * android:value="480" />
 * <meta-data
 * android:name="fontsize"
 * android:value="1.0" />
 * <meta-data
 * android:name="unit"
 * android:value="px" />
 */
public class ScreenAdapter {

    private static LoadViewHelper loadViewHelper;

    public static LoadViewHelper getInstance() {
        return loadViewHelper;
    }

    public static void init(Context context) {
        ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = context.getPackageManager().getApplicationInfo(context
                    .getPackageName(), PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        // 获取标准设计稿的宽高。
        int designwidth = applicationInfo.metaData.getInt("designwidth");
        int designdpi = applicationInfo.metaData.getInt("designdpi");
        float fontsize = applicationInfo.metaData.getFloat("fontsize");
        String unit = applicationInfo.metaData.getString("unit");
        loadViewHelper = new LoadViewHelper(context, designwidth, designdpi, fontsize, unit);
    }

}
